package com.frinder.astar;

/**
 * Created by kiktech on 2018/2/10.
 */
public class Point {

    private int x;
    private int y;
    private String name;

    public Point() {
    }

    private Point(Builder builder) {
        setX(builder.x);
        setY(builder.y);
        name = String.format("%s#%s", x, y);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public String getName() {
        return name;
    }

    public static final class Builder {
        private int x;
        private int y;

        public Builder() {
        }

        public Builder x(int val) {
            x = val;
            return this;
        }

        public Builder y(int val) {
            y = val;
            return this;
        }

        public Point build() {
            return new Point(this);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Point point = (Point) o;
        return x == point.x && y == point.y;
    }

    @Override
    public int hashCode() {
        int result = x;
        result = 31 * result + y;
        return result;
    }

    @Override
    public String toString() {
        return String.format("[%s,%s]", x, y);
    }
}
